const CracoLessPlugin = require('craco-less')
const path = require('path')
const CompressionWebpackPlugin = require('compression-webpack-plugin')

module.exports = {
  eslint: {
    enable: false,
  },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: {},
            javascriptEnabled: true,
          },
        },
      },
    },
  ],
  webpack: {
    configure(webpackConfig, { env, paths }) {
      // 使用gzip压缩超过1M的js和css文件
      webpackConfig.plugins.push(
        new CompressionWebpackPlugin({
          test: /\.js(\?.*)?$/i,
          algorithm: 'gzip',
          compressionOptions: { level: 5 },
        })
      )

      return webpackConfig
    },

    alias: {
      '@': path.resolve(__dirname, 'src'),
      '@biz': path.resolve(__dirname, 'src/biz'),
    },
  },
  //配置代理解决跨域
  devServer: {
    port: 3000,
    proxy: {
      '/car': {
        target: 'https://www.xingcheclub.com', // 直接代理到线上环境，操作需谨慎
        changeOrigin: true,
        secure: true,
        pathRewrite: {
          '^/car': '/car',
        },
      },
    },
  },
}
